/*
 * @Author: your name
 * @Date: 2020-12-26 07:49:57
 * @LastEditTime: 2020-12-26 10:55:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \workSpace\bilibili\src\utils\api.js
 */

import http from "./Request.js";

/**
    * @description: 注册
    * @param {String} url 地址
    * @param {Object} data 传输的数据
    * @return {data} 后端返回值
    */
export function regist(url, data) {
    return http.post(url, data)
}

/**
 * @description:  登录
 * @param {String} url 地址
 * @param {Object} data 参数
 */
export function login(url, data) {
    return http.post(url, data)
}

/**
 * @description: 获取信息
 * @param {String} urlId 
 * @param {Object} headers 
 */
export function getInfo(urlId) {
    return http.get(urlId)
}

/**
 * @description:头像上传到服务器
 * @param {String} url 
 * @param {*} formdata 
 */
export function uploadImg(url, formdata) {
    return http.post(url, formdata)
}
/**
 * @description:修改用数据
 * @param {*} urlId 
 */
export function updateUsers(urlId, data) {
    return http.post(urlId, data)
}

/**
 * @description:导航栏
 * @param {*} url 
 */
export function selectCategory() {
    return http.get('/category/')
}

/**
 * @description:获取栏目内容
 * @param {*} url 
 * @param {*} cateid 
 */
export function getList(cateid, page, pagesize) {
    // return http.get("/detail/" + cateid, {
    //     params: {
    //         page: page,
    //         pagesize: pagesize
    //     }
    // })两种都可以
    return http({
        url: '/detail/' + cateid,
        method: 'get',
        params: {
            page: page,
            pagesize: pagesize
        }
    })
}

/**
 * @description获取文章详情
 * @param {*} id 
 */
export function getArticle(id) {
    return http({
        url: '/article/' + id,
        method: 'get',

    })
}

/**
 * @description 文章页面 随机获取10条推荐数据
 */
export function getCommandData() {
    return http({
        url: '/commend',
        method: 'get'
    })
}

/**
 * @description 获取自身id
 * @param {Number}} id 本地id
 */
export function getMyUserInfo(id) {
    return http({
        url: '/user/' + id,
        method: 'get'
    })
}

/**
 * @description 获取评论
 * @param {*} id 
 */
export function getComment(id) {
    return http({
        url: "/comment/" + id,
        method: "get"

    })
}
/**
 * @description 发表评论
 * @param {*} id 被评论的id
 * @param {*} params 评论内容 
 */
export function Postcomments(id, params) {
    return http({
        url: "/comment_post/" + id,
        method: "post",
        data: params
    })
}

/**
 * @description 收藏
 * @param {*} params 
 */
export function saveArticle(id, params) {
    return http({
        url: "/collection/" + id,
        method: "post",
        data: params
    })
}
/**
 * @description 判断是否收藏
 * @param {*} id 用户的id 
 */
export function isSave(id, params) {
    return http({
        url: "/collection/" + id,
        method: "get",
        params: params
    })
}

